<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"
    />
    <title>观察者模式</title>
</head>

<body>
    <script type="text/javascript">
        function Foo() {
            this.value = 42
        }
        Foo.prototype = {
            method: function () { }
        };

        function Bar() { }

        // 设置Bar的prototype属性为Foo的实例对象
        Bar.prototype = new Foo()
        Bar.prototype.foo = 'Hello World'

        // 修正Bar.prototype.constructor为Bar本身
        Bar.prototype.constructor = Bar

        var test = new Bar() // 创建Bar的一个新实例
        var test1 = new Bar() // 创建Bar的一个新实例

        test.value =1
        console.log(test.value)
        console.log(test1.value)
    </script>

</body>

</html>